package com.upay.android.controller.fragment;

import android.app.Activity;
import android.app.ListFragment;
import android.content.SharedPreferences;

import com.upay.android.controller.activity.FragmentActivity;
import com.upay.android.controller.helper.Keys;
import com.upay.android.domain.authentication.AuthenticationToken;

public abstract class AbstractListFragment extends ListFragment implements UPayFragment {

	/* ---- Constants ---- */
	
	/* ---- Instance Variables ---- */
	
	/* ---- Constructors ---- */
	
	/* ---- Business Methods ---- */
	
	public FragmentActivity getContext() {
		Activity activity = getActivity();
		if (activity instanceof FragmentActivity) {
			return (FragmentActivity)activity;
		} else {
			throw new UnsupportedOperationException();
		}	
	}
	
	protected AuthenticationToken getAuthenticationToken() {
	    SharedPreferences sharedPreferences = getContext().getSharedPreferences(Keys.UPAY_PREFERENCES, 0);
	    return new AuthenticationToken(
	    	sharedPreferences.getString(Keys.USERID, null),
	    	sharedPreferences.getString(Keys.TOKEN, null));
	}
	
	/* ---- Getters and Setters ---- */
	
}
